from django.db import models


class User(models.Model):
    status_choice=((1,"激活"),(2,"未激活"))
    #用户名
    username=models.CharField(max_length=200,null=True)
    #密码
    password=models.CharField(max_length=200)
    #手机号
    phone=models.CharField(max_length=11,null=True)
    #邮箱
    email=models.EmailField(null=True)
    #状态
    status=models.SmallIntegerField(choices=status_choice,default=1)
    #头像
    photo=models.ImageField(upload_to="static/upload",null=True)
    class Meta:
        db_table='user'

#三方登录
class OpenUser(models.Model):
    TYPE_CHOICES=((1, "微博"), (2, "微信"), (3, "支付宝"))
    uid=models.CharField(max_length=20)
    type=models.SmallIntegerField(choices=TYPE_CHOICES, default=1)
    user= models.ForeignKey(User, on_delete=models.CASCADE, null=True)

    class Meta:
        db_table="opem_user"

class UserDeng(models.Model):
    name = models.CharField(max_length=20)
    age = models.IntegerField()
    def __str__(self):
        return self.name

class Follw(models.Model):
    idol = models.ForeignKey(UserDeng,on_delete=models.CASCADE,related_name='idol')
    fans = models.ForeignKey(UserDeng,on_delete=models.CASCADE,related_name='fans')
    #
    # class Meta:
    #     unique_together = ('idol','fans')
    # def __str__(self):
    #     return '%s关注了%s'%(self.fans.name,self.idol.name)

class Teacher(models.Model):
    """
    老师表
    """
    name = models.CharField(max_length=100, null=True, verbose_name='老师名')


class Laber(models.Model):
    """
    标签表
    """
    name = models.CharField(max_length=200, null=True, verbose_name='标签')


class Stage(models.Model):
    """
    阶段表
    """
    name = models.CharField(max_length=234, null=True, verbose_name='阶段名')


class Coures(models.Model):
    """
    课程表
    """

    title = models.CharField(max_length=150, null=True, verbose_name='课程标题')
    pic = models.CharField(max_length=150, null=True, verbose_name='课程图片')
    info = models.CharField(max_length=150, null=True, verbose_name='课程简介')
    online = models.IntegerField(default=0, verbose_name='是否上线，0没上线，1上线')
    member = models.IntegerField(default=0, verbose_name='是否会员，0非会员，1会员，2训练营')
    atention = models.IntegerField(null=True, verbose_name='关注量')
    learn = models.IntegerField(null=True, verbose_name='学过人数')
    teacher = models.ForeignKey(Teacher, null=True, on_delete=models.CASCADE, verbose_name='老师外键')
    Comment_num = models.IntegerField(null=True, verbose_name='评论数')
    path = models.ForeignKey(Stage, null=True, on_delete=models.CASCADE, verbose_name='阶段外键')
    tag = models.ForeignKey(Laber, null=True, on_delete=models.CASCADE, verbose_name='标签外键')
    recommand = models.CharField(max_length=100, null=True, verbose_name='推荐课程')
    detail = models.CharField(max_length=100, null=True, verbose_name='课程详情')
    Section_num = models.IntegerField(null=True, verbose_name='章节数')


class Section(models.Model):
    """
    课程章节表
    """
    course = models.ForeignKey(Coures, null=True, on_delete=models.CASCADE, verbose_name='课程外键')
    section = models.CharField(max_length=123, null=True, verbose_name='课程章节名称')
    video = models.CharField(max_length=132, null=True, verbose_name='视频链接')
    sort = models.IntegerField(null=True, verbose_name='排序')


class Record(models.Model):
    """
    学习记录表
    """
    course_id = models.ForeignKey(Coures, null=True, on_delete=models.CASCADE, verbose_name='课程外键')
    user_id = models.ForeignKey(User, null=True, on_delete=models.CASCADE, verbose_name='用户外键')
    section_id = models.ForeignKey(Section, null=True, on_delete=models.CASCADE, verbose_name='章节外键')
    status = models.IntegerField(default=0, verbose_name='完成状态0未完成1完成')


class Course_collect(models.Model):
    """
    课程收藏表
    """
    User_id = models.IntegerField(null=True, verbose_name='用户id')
    Course_id = models.IntegerField(null=True, verbose_name='课程id')


class Comment(models.Model):
    """
    评论表
    """
    content = models.CharField(max_length=245, null=True, verbose_name='评论内容')
    pid = models.IntegerField(default=0, null=True, verbose_name='上一级评论id')
    top = models.IntegerField(default=0, null=True, verbose_name='顶级评论id')
    type_id = models.IntegerField(default=0, null=True, verbose_name='自身评论id')
    user_id = models.IntegerField(null=True, verbose_name='用户id')
    course = models.IntegerField(null=True, verbose_name='课程id')
    comment_type = models.CharField(null=True, max_length=100,verbose_name='评论类型')
    status = models.IntegerField(default=0, verbose_name='审核状态(0否1是)')
    reason = models.CharField(max_length=245, null=True)


class Report(models.Model):
    """
    实验报告表
    """
    section_id = models.IntegerField(null=True, verbose_name='章节id')
    user_id = models.IntegerField(null=True, verbose_name='用户id')
    report_content = models.CharField(max_length=100, null=True, verbose_name='报告内容')
    report_title = models.CharField(null=True,max_length=100, verbose_name='报告标题')
    report_browse = models.IntegerField(null=True, verbose_name='实验报告浏览量')
    linknum = models.IntegerField(null=True, verbose_name='点赞数')
    coures_id = models.ForeignKey(Coures, null=True, on_delete=models.CASCADE, verbose_name='课程id')


class Answer(models.Model):
    """
    实验问答
    """
    course_id = models.IntegerField(null=True, verbose_name='课程id')
    answer_content = models.CharField(null=True,max_length=100, verbose_name='问答标题')
    answer_title = models.CharField(null=True, max_length=100,verbose_name='问答内容')
    browse_id = models.IntegerField(null=True, verbose_name='浏览量')
    user_id = models.IntegerField(null=True, verbose_name='用户id')
    pid = models.IntegerField(default=0, verbose_name='上一级的评论id')
    top = models.IntegerField(default=0, verbose_name='顶级评论id')
    type_id = models.IntegerField(default=0, verbose_name='自身级别id')


class Collect(models.Model):
    """
    用户和收藏实验问答报告表
    """
    user_id = models.IntegerField(null=True, verbose_name='用户id')
    find_id = models.IntegerField(null=True, verbose_name='实验问答id/实验id')
    collect_tpye = models.IntegerField(null=True, verbose_name='收藏类型(0实验报告/1实验问答)')
